//quick'n'dirty hash function
//$Id: calc_hash.h 589 2010-11-07 17:28:23Z Oleg.Bulychov $
#pragma once

/*
An algorithm produced by Professor Daniel J. Bernstein and shown first to
the world on the usenet newsgroup comp.lang.c. It is one of the most efficient
hash functions ever published.
*/
unsigned Calc_Hash(void const* pv, size_t cb, unsigned hash = 5381)
{
    char const* pb = (char const*)pv;
    for(size_t i = 0; i < cb; ++i)
        hash = ((hash << 5) + hash) + pb[i];
    return hash;
}

//EOF!
